package org.mock.sample.cars;

public enum Gear {
    NEUTRAL(0),
    ONE(1),
    TWO(2),
    THREE(3),
    FOUR(4),
    FIVE(5);
    
    int level;
    
    private Gear(int level){
        this.level = level; 
    }
    
    public Gear down(){
        if (this == NEUTRAL) return NEUTRAL;
        return resolve (this.level-1);
        
    }
    
    public Gear up(){
        if (this == FIVE) return FIVE;
        return resolve (this.level+1);
    }
    
    
    private Gear resolve (int level){
        for (Gear current : Gear.values()) {
            if (current.level == level) return current;
        }
        return null;
        
    }
}

